package br.unifor.ow2.onaga.cloud.testsuite;


import java.io.InputStream;
import java.io.InputStreamReader;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.YamlReader;

import br.unifor.ow2.onaga.cloud.model.Test;

public class TestLoader {
	public static Test loadTest(InputStream in) throws YamlException{
		YamlReader reader = new YamlReader(new InputStreamReader(in));
		reader.getConfig().setClassTag("instance",br.unifor.ow2.onaga.cloud.model.Instance.class);
		reader.getConfig().setClassTag("scenario",br.unifor.ow2.onaga.cloud.model.Scenario.class);
		
		reader.getConfig().setClassTag("test",br.unifor.ow2.onaga.cloud.model.Test.class);
		reader.getConfig().setPropertyElementType(br.unifor.ow2.onaga.cloud.model.Test.class, "instances", br.unifor.ow2.onaga.cloud.model.Instance.class);
		reader.getConfig().setPropertyElementType(br.unifor.ow2.onaga.cloud.model.Test.class, "scenarios", br.unifor.ow2.onaga.cloud.model.Scenario.class);
		reader.getConfig().setPropertyElementType(br.unifor.ow2.onaga.cloud.model.Scenario.class, "instances", br.unifor.ow2.onaga.cloud.model.Instance.class);
		
		
		Test test = (Test) reader.read();
		
		return test;
	}
	
	public static void main(String[] args) {
		try {
			loadTest(TestLoader.class.getClass().getResourceAsStream(
			"/br/teste_1.yml"));
		} catch (YamlException e) {			
			e.printStackTrace();
		}
	}
}
